<template>
	<view class="container">
		<view class="chat-list">
			<view class="chat-item left">
				<image class="avatar"></image>
				<view class="content">
					<text class="message">{{data.content}}</text>
				</view>
			</view>
			<view class="chat-item right" v-for="(item, index) in myMessages" :key="index">
				<view class="content">
					<text class="message">{{item.content}}</text>
				</view>
				<image class="avatar" :src="userInfo.avatar"></image>
			</view>
		</view>
		<view class="input-area">
			<input class="input" v-model="inputText" placeholder="请输入消息" />
			<view class="input-but">
				<button class="send-btn" @click="sendMessage">发送</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				"data": [{
					"id": 1,
					"title": "",
					"content": "",
					"date": "",
					"name": ""
				}],
				inputText: '',
				userInfo: null,
				myMessages: [{
					"id": 2,
					"title": "你好",
					"content": "你好",
					"date": "2024-10-32",
					"name": "啊哈"
				}]
			}
		},
		onLoad(e) {
			let id = e.id
			uni.request({
				url: 'http://localhost:8090/freshmenapp/message/findone',
				method: 'POST',
				data: {
					id: id
				},
				success: res => {
					this.data = res.data.data
				},
				fail: () => {},
				complete: () => {}
			});

			// 获取用户信息
			this.userInfo = uni.getStorageSync('userinfo')
		}
	}
</script>

<style>
	.container {
		display: flex;
		flex-direction: column;
		height: 100%;
	}

	.chat-list {
		height: 1090rpx;
		padding: 20rpx;
	}

	.chat-item {
		display: flex;
		margin-bottom: 20rpx;
	}

	.left {
		justify-content: flex-start;
	}

	.right {
		justify-content: flex-end;
	}

	.avatar {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
	}

	.content {
		max-width: 400rpx;
		padding: 20rpx;
		border-radius: 10rpx;
	}

	.left .content {
		margin-left: 20rpx;
		background-color: #f0f0f0;
	}

	.right .content {
		margin-right: 20rpx;
		background-color: #007aff;
		color: #fff;
	}

	.name {
		font-size: 24rpx;
		margin-bottom: 10rpx;
	}

	.message {
		font-size: 32rpx;
	}

	.input-area {
		display: flex;
		align-items: center;
		padding: 20rpx;
		background-color: #f8f8f8;
	}

	.input {
		flex: 1;
		height: 80rpx;
		padding: 0 20rpx;
		background-color: #fff;
		border-radius: 40rpx;
		font-size: 32rpx;
	}

	.send-btn {
		margin-left: 20rpx;
		padding: 0 40rpx;
		height: 80rpx;
		background-color: #007aff;
		color: #fff;
		border-radius: 40rpx;
		font-size: 32rpx;
	}
</style>